var app = getApp();
Page({
  data: {
    ischeck: false,
    page: {
      isend: false,
      doing: false,
      doo: 'article',
      pdata: {
        op: 'list',
        page: 1,
        actsort: 0,
      },
      waitf: 0,
      nodataf: 0,
    },
    datalist: [],
    bar: {},
    artsort: [],
  },
  onLoad: function (options) {
    var self = this;
    app.com.getPage(self, self.data.page, 20, function (res) {
      var data = res.data.data;

      self.setData({
        datalist: data.art,
        bar: data.bar.data,
        artsort: data.artsort,
      });


      /*if( self.data.bar.bgcolor ) {
          wx.setNavigationBarColor({
              frontColor  : 'wilte',
              backgroundColor: self.data.bar.bgcolor,
          });
      }*/

    }, false, function (res) {
      app.util.message(res.data.message, '', 'error');
    });

    wx.setNavigationBarTitle({
      title: '文章列表'
    });

  },
  onReady: function () {
    var self = this;
    // 页面渲染完成
  },
  onShareAppMessage: function () {
    var self = this;
    return {
      title: '文章列表',
      path: '',
    }
  },

  onReachBottom: function () {
    var self = this;

    app.com.getPage(self, self.data.page, 20, function (res) {
      self.setData({
        datalist: self.data.datalist.concat(res.data.data)
      });
    });
  },
  toarticle: function (e) {

    var self = this;
    var url = e.currentTarget.dataset.url;

    if (url) {
      wx.navigateTo({
        url: url
      });
    }
  },
  changeSort: function (e) {
    var self = this;
    var id = e.currentTarget.dataset.id;

    self.setData({
      'page.pdata.actsort': id,
      'page.pdata.page': 1,
      'page.isend': false,
      'page.waitf': 0,
      'page.nodataf': 0
    });
    app.com.getPage(self, self.data.page, 20, function (res) {
      self.setData({
        datalist: res.data.data.art
      });

    });
  },
  location: function (e) {
    //console.log( e.currentTarget.dataset.lat );
    wx.openLocation({
      latitude: parseFloat(e.currentTarget.dataset.lat),
      longitude: parseFloat(e.currentTarget.dataset.lng),
      scale: 13
    })
  },
  otherapp: function (e) {

    wx.navigateToMiniProgram({
      appId: e.currentTarget.dataset.appid,
      path: e.currentTarget.dataset.appurl,
      success: function () {
        console.log('tosuc');
      },
      fail: function (m) {
        console.log(m)
        app.util.message('打开页面失败', '', 'error');
      }
    })
  },
  navigateto: function (e) {
    if (e.currentTarget.dataset.url) {
      wx.navigateTo({
        url: e.currentTarget.dataset.url
      })
    }
  },
  redirectto: function (e) {
    if (e.currentTarget.dataset.url) {
      wx.redirectTo({
        url: e.currentTarget.dataset.url
      })
    }
  },
  callphone: function (e) {

    var tel = e.currentTarget.dataset.tel;
    if (tel) {
      wx.makePhoneCall({
        phoneNumber: tel
      });
    }
  },

})